# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=commix
pkgver=2334.c56e9ec9
pkgrel=1
groups=('blackarch' 'blackarch-webapp' 'blackarch-automation'
        'blackarch-exploitation')
pkgdesc='Automated All-in-One OS Command Injection and Exploitation Tool.'
arch=('any')
url='https://github.com/commixproject/commix'
license=('custom:unknown' 'AGPL')
depends=('python' 'python-scapy')
makedepends=('git')
source=("git+https://github.com/commixproject/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  sed -i '20 i\from os.path import expanduser' commix/src/utils/settings.py
  sed -i \
    's|OUTPUT_DIR = ".output/"|OUTPUT_DIR = expanduser("~") + "/commix-output/"|' \
    commix/src/utils/settings.py

  #patch -p1 < settings.py.patch
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md doc/AUTHOR \
    doc/CHANGELOG.md doc/THANKS.md doc/translations/* COMMITMENT.txt
  install -Dm 644 LICENSE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  rm -rf README.md doc/ LICENSE.txt COMMITMENT.txt

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

